import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_paint/day_4/custom_canvas_image.dart';
import 'dart:ui' as ui;
///
/// [author]: liMing
/// [Date]: 2021-08-17  00:20
///
class Paper extends StatefulWidget {
  @override
  _PaperState createState() => _PaperState();
}

class _PaperState extends State<Paper> {
  ui.Image _image;

  @override
  void initState() {
    loadImage();
    super.initState();
  }
  void loadImage ()async{
    _image =
        await loadImageFromAssets('images/light.jpeg');
    setState(() {

    });
  }
  Future<ui.Image> loadImageFromAssets(String path)async{
    ByteData byteData = await rootBundle.load(path);
    List<int> bytes = byteData.buffer.asUint8List(byteData.offsetInBytes,byteData.lengthInBytes);
    print('${bytes.length}');
    return decodeImageFromList(bytes);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: CustomPaint(
        painter:CustomCanvasImage(_image) ,
      ),
    );
  }
}
